package com.bjpowernode.controller;

import com.bjpowernode.entity.TActivity;
import com.bjpowernode.entity.TActivityRemark;
import com.bjpowernode.query.ActivityQuery;
import com.bjpowernode.query.ActivityRemarkQuery;
import com.bjpowernode.result.R;
import com.bjpowernode.service.ActivityRemarkService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
public class ActivityRemarkController {

    @Resource
    private ActivityRemarkService activityRemarkService;

    /**
     * 提交活动备注
     *
     * @param activityRemarkQuery
     * @return
     */
    @PostMapping(value = "/api/activity/remark")
    public R addActivityRemark(@RequestBody ActivityRemarkQuery activityRemarkQuery) {
        int save = activityRemarkService.saveActivityRemark(activityRemarkQuery);
        return save >= 1 ? R.OK() : R.FAIL();
    }

    @GetMapping(value = "/api/activity/remarks")
    public R activityPage(@RequestParam(value = "current", required = false) Integer current,
                          @RequestParam(value = "activityId") Integer activityId) {
        // required = false 表示current参数可以传，也可以不传，也就是current参数可以是空的；
        // required = true 表示current参数必须传，不传会报错；
        if (current == null) {
            current = 1;
        }
        PageInfo<TActivityRemark> pageInfo = activityRemarkService.getActivityRemarkPage(current, activityId);
        return R.OK(pageInfo);
    }

    @GetMapping(value = "/api/activity/remark/{id}")
    public R activityRemark(@PathVariable(value = "id") Integer id) {
        //id 是活动标注表的主键id，不是活动表的id
        TActivityRemark tActivityRemark = activityRemarkService.getActivityRemarkById(id);
        return R.OK(tActivityRemark);
    }

    /**
     * 编辑市场活动备注
     *
     * @param activityRemarkQuery
     * @return
     */
    @PutMapping(value = "/api/activity/remark")
    public R updateActivityRemark(@RequestBody ActivityRemarkQuery activityRemarkQuery) {
        int update = activityRemarkService.updateActivityRemark(activityRemarkQuery);
        return update >= 1 ? R.OK() : R.FAIL();
    }

    @DeleteMapping(value = "/api/activity/remark/{id}")
    public R delActivityRemark(@PathVariable(value = "id") Integer id) {
        int del = activityRemarkService.delActivityRemarkById(id);
        return del >= 1 ? R.OK() : R.FAIL();
    }
}

